﻿// ***********************************************************************
// Assembly         : WcfService
// Created          : 05-13-2014
//
// Last Modified By : Kristian
// Last Modified On : 05-13-2014
// ***********************************************************************
using CtrLayer;
using ModelLayer;
using System.Collections.Generic;

namespace WcfService
{
    /// <summary>
    /// Class RealLifeService implements interface IRealLifeService.
    /// </summary>
    public class RealLifeService : IRealLifeService
    {
        private ICtrUser _ctrUser;
        private ICtrLogin _ctrLogin;
        private ICtrAchievement _ctrAchievement;

        /// <summary>
        /// Initializes a new instance of the <see cref="RealLifeService"/> class.
        /// </summary>
        public RealLifeService()
        {
            _ctrUser = new CtrUser();
            _ctrLogin = new CtrLogin();
            _ctrAchievement = new CtrAchievement();
        }

        /// <summary>
        /// Validates the login information.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="password">The password.</param>
        /// <returns><c>true</c> if email and password are present for a user, <c>false</c> otherwise.</returns>
        public int ValidateLoginInformation(string email, string password)
        {
            return _ctrLogin.ValidateLogin(email, password);
        }

        /// <summary>
        /// Gets the user with the given email-password combination.
        /// </summary>
        /// <param name="email">The email.</param>
        /// <param name="password">The password.</param>
        /// <returns>User.</returns>
        public User GetUser(string email, string password)
        {
            return _ctrUser.GetUser(email, password);
        }

        /// <summary>
        /// Creates a new user in the database.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>System.Int32.</returns>
        public int CreateUser(User user)
        {
            return _ctrUser.CreateUser(user);
        }

        /// <summary>
        /// Creates a new Achievement in the database.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="achievement">The Achievement.</param>
        /// <returns>System.Int32.</returns>
        public int CreateAchievement(User user, Achievement achievement)
        {
            return _ctrAchievement.CreateAchievement(user, achievement);
        }

        /// <summary>
        /// Gets the friendships related to a given user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>List{User}.</returns>
        public List<User> GetFriendships(User user)
        {
            return _ctrUser.GetFriendships(user);
        }

        /// <summary>
        /// Gets the user achievements related to a given user.
        /// </summary>
        /// <param name="myUser">My user.</param>
        /// <returns>List{UserAchievement}.</returns>
        public List<UserAchievement> GetUserAchievements(User myUser)
        {
            return _ctrAchievement.GetUserAchievements(myUser);
        }

        /// <summary>
        /// Gets the pending friendships related to a given user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>List{User}.</returns>
        public List<Friend> GetPendingFriendships(User user)
        {
            return _ctrUser.GetPendingFriendships(user);
        }

        public int SetUserAchievementStatus(UserAchievement userAchievement)
        {
            return _ctrAchievement.SetUserAchievementStatus(userAchievement);
        }

        public int RequestFriendship(User requester, User requested)
        {
            return _ctrUser.RequestFriendship(requester, requested);
        }

        public List<User> SearchUserList(string[] keywords)
        {
            return _ctrUser.SearchUserList(keywords);
        }

        public int SetFriendshipStatus(User requester, User accepter, Friend.Status status)
        {
            return _ctrUser.SetFriendshipStatus(requester, accepter, status);
        }

        public int SetAchievementStatus(Achievement achievement)
        {
            return _ctrAchievement.SetAchievementStatus(achievement);
        }

        public User GetUserById(int id)
        {
            return _ctrUser.GetUser(id);
        }

        public UserAchievement GetUserAchievement(int userId, int achId)
        {
            return _ctrAchievement.GetUserAchievement(userId, achId);
        }


        public int DeleteUsers(int[] userIDs)
        {
          return _ctrUser.DeleteUsers(userIDs);
        }
    }
}